/**
 * @Author:周邱艳
 * @Date:2020/6/30
 * @Description:这是成分产品名称
 */
import React,{Component} from "react";
import { List } from 'antd-mobile';
import axios from "axios";
import {URL} from "../../../index";
var data_list=[]
const Item = List.Item;
// 将获取的数据中属性为数字的转换为文字
function numberName(newList){
    for(let i=0;i<newList.length;i++) {
        //规范组合产品的收益率
        var ratio = newList[i].comShareRadio;
        newList[i].comShareRadio = Number(ratio*100).toFixed(2)+"%";

    }
    return newList;
};


export default class ProductNameGain extends Component{
    //返回图的配置对象
    constructor(props) {
        super(props);
        this.state={
            disabled: false,
            products:[],//总表
            isShow:false,
            data_list:[]

        }
        this.getCategorys=this.getCategorys.bind(this)
    }
    getCategorys = () => {
        //数据请求
        axios({
            method:"GET",
            url:"http://39.101.141.248:9527/proYields/proYieldByCombinationId",
             params:{comBaseId:this.props.fathercomBaseId}//
        }).then(
            (res) => {
                //状态码判断
                if(res.data.code===200){
                    data_list=numberName(res.data.products)
                    //数据更新
                    this.setState({
                        products: this.state.products.concat(res.data.products),

                    })
                    //状态码判断
                }

            }
        ).catch(function (error) {//异常处理
            console.log(error);
        })
    }
    //组件挂载后
    componentDidMount() {
        this.getCategorys()

    }

    render() {
        return (
            <div>
                <List className="my-list">
                    <Item extra={<p style={{fontSize:"1.8rem",color:"grey"}}>占比</p>}
                         ><p style={{fontSize:"1.8rem",color:"grey"}}>成分产品名称</p></Item>
                </List>
                {(()=>{return this.state.products.map((item,index)=>{
                    return(
                        <List className="my-list">
                            <Item extra={<p style={{fontSize:"1.8rem",color:"red"}}>{item.comShareRadio}</p>}
                                  style={{fontSize:"2.5rem",color:"black"}}>{item.proName}</Item>
                        </List>
                    )
                })
                })()}
            </div>
        );
    }
}
